
#ifndef __NEW_KEY_DB_H
#define __NEW_KEY_DB_H

#include <vector>
#include "SQLiteDB.h"
#include "KeyTableView.h"

#include "../crypt/keys.h"

#define KEY_GENERATE_TYPE_ROOT_ENCRYPT_DECRYPT    KEY_ASYMMETRIC_PAIR_RSA
#define KEY_GENERATE_TYPE_LEAF_ENCRYPT_DECRYPT    KEY_SYMMETRIC_AES
#define KEY_GENERATE_TYPE_ROOT_CHECKING_SIGNING   KEY_ASYMMETRIC_PAIR_RSA
#define KEY_GENERATE_TYPE_LEAF_CHECKING_SIGNING   KEY_ASYMMETRIC_PAIR_RSA

#define ENCRYPTION_KEYTABLE_NAME "encryption_keys"
#define DECRYPTION_KEYTABLE_NAME "decryption_keys"
#define SIGNING_KEYTABLE_NAME    "signing_keys"
#define CHECKING_KEYTABLE_NAME   "checking_keys"

#define KEYMARK_DELETE      '0'
#define KEYMARK_DELETEIN1   '1'
#define KEYMARK_DELETEIN2   '2'
#define KEYMARK_DELETEIN3   '3'
#define KEYMARK_EXPENDABLE  'E'
#define KEYMARK_CHAINLATEST 'L'
#define KEYMARK_CHAIN       'C'
#define KEYMARK_CHAINROOT   'R'
#define KEYMARK_PERMANENT   'P'

class NewKeyDB : public SQLiteDB
{
   private:
      std::vector<const char *> *GetTableNamesFromCreateTablesIfNecessary();
      KeyTableView *encryptionkeys;
      KeyTableView *decryptionkeys;
      KeyTableView *signingkeys;
      KeyTableView *checkingkeys;
      std::vector<const char *> *keytablenames;
   public:
      NewKeyDB(const char *filename, const char *WIPpwd, const char *ownname, const char *ownpwd, int persists);
      ~NewKeyDB();
      int GenerateEncDecPairIntoDB(int ischained, int isexpendable,
         const char *name, const char *pwd, const char *owner);
      int GenerateSgnChkPairIntoDB(int ischained, int isexpendable,
         const char *name, const char *pwd, const char *owner);
      static int GenerateNewEncryptionDecryptionKeys(int ischainroot, const char *name, EncryptionKey **enckey, DecryptionKey **deckey);
      static int GenerateNewSigningCheckingKeys(int ischainroot, const char *name, SigningKey **sgnkey, CheckingKey **chkkey);
};

#endif
